package com.ilia.slitok;

import static com.ilia.slitok.Constants.NULL_COORD;
import static com.ilia.slitok.Constants.NUMBER_OF_COORD;

import java.util.Comparator;

public class PolyAlloyTargetAlloyComparator implements Comparator<PolyAlloy>{

  private int[] target;
  public PolyAlloyTargetAlloyComparator(int[] target_coord) {
    this.target = target_coord;
    if (target==null) {
      target = NULL_COORD;
    }
  }
  @Override
  public int compare(PolyAlloy arg0, PolyAlloy arg1) {
      int d1 = distance(arg0.box);
      int d2 = distance(arg1.box);
      return d1-d2;
  }
  
//  public static int distanceSimpleSquare(int[] item, int[] target) {
//    int d=0;
//    for (int i = 0; i < NUMBER_OF_COORD; i++) {
//      int r = (item[i]-target[i])*(item[i]-target[i]);
//      d +=r;
//    }
//    return d;
//  }
  
  public int distance(int[] item) {
    int d=0;
    for (int i = 0; i < NUMBER_OF_COORD; i++) {
      int r = (item[i]-target[i])*(item[i]-target[i]);
      d +=r;
    }
    return d;
  }

}
